package ginplus

import (
	"github.com/gin-gonic/gin"
	"sync/atomic"
)

var defaultConfig atomic.Pointer[WebContext]

func init() {
	gin.SetMode(gin.ReleaseMode)
	SetWebContext(NewWebContext(gin.Default()))
}

func SetWebContext(config *WebContext) {
	defaultConfig.Store(config)
}

func defaultWebContext() *WebContext {
	return defaultConfig.Load()
}

// StartHttpServer 启动http服务
func StartHttpServer(setConfig func(webCtx *WebContext, engine *gin.Engine)) {
	ctx := defaultWebContext()
	setConfig(ctx, ctx.ginEngine)
	ctx.StartHttpServer()
}
